home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / MAG04.ZIP / MAG04.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-27  |  6.2 KB  |  266 lines

  1. Program Static_Screen;
  2.  
  3. Uses Crt;                       { CRT has some good general routines in it }
  4.  
  5. Const VGA=$A000;
  6.  
  7. Type RgbItem=Record
  8.                    R,G,B:Byte;
  9.              End;
  10.      RgbList=Array[0..255] of RgbItem;
  11.  
  12. Var Pal1:RgbList;
  13.     X1,Y1,X2,Y2:Word;
  14.     Ix1,Ix2,Iy1,Iy2:ShortInt;
  15.     Col:Byte;
  16.     C:Char;
  17.     R:Word;
  18.  
  19. Procedure Initgraph; Assembler;
  20. Asm
  21.    Mov AH,0
  22.    Mov AL,13h
  23.    Int 10h
  24. End;
  25.  
  26. Procedure Closegraph; Assembler;
  27. Asm
  28.    Mov AH,0
  29.    Mov AL,03h
  30.    Int 10h
  31. End;
  32.  
  33. Procedure WaitVBL; Assembler;
  34. Label A1,A2;
  35. Asm
  36.    Mov DX,3DAh
  37.    A1:
  38.       In AL,DX
  39.       And AL,08h
  40.       Jnz A1
  41.    A2:
  42.       In AL,DX
  43.       And AL,08h
  44.       Jz A2
  45. End;
  46.  
  47. Procedure PutPixel(X,Y,C:Word);
  48. Begin
  49.      Mem[VGA:(Y*320)+X]:=C;
  50. End;
  51.  
  52. Procedure GetColor(Col:Byte;Var R,G,B:Byte);
  53. Begin
  54.      Port[$3C7]:=Col;
  55.      R:=Port[$3C9];
  56.      G:=Port[$3C9];
  57.      B:=Port[$3C9];
  58. End;
  59.  
  60. Procedure SetColor(Col,R,B,G:Byte);
  61. Begin
  62.      Port[$3C8]:=Col;
  63.      Port[$3C9]:=R;
  64.      Port[$3C9]:=G;
  65.      Port[$3C9]:=B;
  66. End;
  67.  
  68. Procedure GetPalette(Var Pal:RgbList);
  69. Var A:Byte;
  70. Begin
  71.      For A:=0 To 255 do GetColor(A,Pal[A].R,Pal[A].G,Pal[A].B);
  72. End;
  73.  
  74. Procedure SetPalette(Pal:RgbList);
  75. Var A:Byte;
  76. Begin
  77.      WaitVBL;
  78.      For A:=0 To 255 do SetColor(A,Pal[A].R,Pal[A].G,Pal[A].B);
  79. End;
  80.  
  81. Procedure SetBlack(Var Pal:RgbList);
  82. Var A:Byte;
  83. Begin
  84.      For A:=0 to 255 Do
  85.      Begin
  86.           Pal[A].R:=0;
  87.           Pal[A].G:=0;
  88.           Pal[A].B:=0;
  89.      End;
  90. End;
  91.  
  92. Procedure Cls(Col:Byte);
  93. Begin
  94.      FillChar(Mem[$A000:0000],64000,Col);
  95. End;
  96.  
  97. Procedure RotatePal(Var Pal:RgbList;First,Last:Byte);
  98. Var Temp:RgbItem;
  99.     A:Byte;
  100. Begin
  101.      Temp:=Pal[Last];
  102.      For A:=Last-1 DownTo First Do
  103.      Begin
  104.           Pal[A+1]:=Pal[A];
  105.      End;
  106.      Pal[First]:=Temp;
  107. End;
  108.  
  109. Procedure LoadPal(Filename:String;Var Pal:RgbList); { This loads a palette    }
  110. Var F:File;                                         { from disk... I will     }
  111. Begin                                               { explain it in a future  }
  112.      Assign(F,Filename);                            { article, all about disk }
  113.      Reset(F,1);                                    { access...               }
  114.      Blockread(F,Ptr(Seg(Pal[0].R),Ofs(Pal[0].R))^,768);
  115.      Close(F);
  116. End;
  117.  
  118. Procedure InitLines;
  119. Begin
  120.      X1:=180;
  121.      Y1:=100;
  122.      X2:=150;
  123.      Y2:=140;
  124.      Ix1:=3-Random(6); If Ix1=0 Then Ix1:=1;
  125.      Iy1:=3-Random(6); If Iy1=0 Then Iy1:=1;
  126.      Ix2:=3-Random(6); If Ix2=0 Then Ix2:=1;
  127.      Iy2:=3-Random(6); If Iy2=0 Then Iy2:=1;
  128.      Col:=2;
  129.      LoadPal('Mag04.Pal',Pal1);
  130.      SetPalette(Pal1);
  131.      Cls(0);
  132. End;
  133.  
  134. Procedure Circle(X,Y,R:Integer;Col:Byte);
  135. Var Px,Py:Integer;
  136.     Deg:Real;
  137. Begin
  138.      Deg:=0;
  139.      Repeat
  140.            Px:=Round(R*Sin(Deg))+X;
  141.            Py:=Round(R*Cos(Deg))+Y;
  142.            PutPixel(Px,Py,Col);
  143.            Deg:=Deg+0.005;
  144.      Until Deg>2*PI;
  145. End;
  146.  
  147. Procedure Circles;
  148. Begin
  149.      LoadPal('Mag04.Pal',Pal1);
  150.      SetPalette(Pal1);
  151.      For R:=1 To 99 Do Circle(160,100,R,R*2);
  152.      Repeat
  153.            If Keypressed Then If Readkey=Chr(27) Then Exit;
  154.            RotatePal(Pal1,1,255);
  155.            SetPalette(Pal1);
  156.      Until False;
  157. End;
  158.  
  159. Function sgn(A:Real):Integer;
  160. Begin
  161.      If A>0 then Sgn:=+1;
  162.      If A<0 then Sgn:=-1;
  163.      If A=0 then Sgn:=0;
  164. End;
  165.  
  166. Procedure Line(X1,Y1,X2,Y2,Col:Integer);
  167. Var Deltax,S,Deltay,Dx1,Dy1,Dx2,Dy2,S1,S2:Real;
  168.     I:Integer;
  169. Begin
  170.      Deltax:=X2-X1;
  171.      Deltay:=Y2-Y1;
  172.      Dx1:=Sgn(Deltax);
  173.      Dy1:=Sgn(Deltay);
  174.      Dx2:=Sgn(Deltax);
  175.      Dy2:= 0;
  176.      S1:=Abs(Deltax);
  177.      S2:=Abs(Deltay);
  178.      If Not (S1>S2) Then
  179.      Begin
  180.           Dx2:=0;
  181.           Dy2:=Sgn(Deltay);
  182.           S1:=Abs(Deltay);
  183.           S2:=Abs(Deltax);
  184.      End;
  185.      S:=Int(S1/2);
  186.      For I:=0 To Round(S1) Do
  187.      Begin
  188.           PutPixel(X1,Y1,Col);
  189.           S:=S+S2;
  190.           If Not (S<S1) Then
  191.           Begin
  192.                S:=S-S1;
  193.                X1:=X1+Round(Dx1);
  194.                Y1:=Y1+Round(Dy1);
  195.           End
  196.           Else
  197.           Begin
  198.                X1:=X1+Round(dx2);
  199.                Y1:=Y1+Round(Dy2);
  200.           End;
  201.      End;
  202. End;
  203.  
  204. Procedure Lines;
  205. Begin
  206.      Repeat
  207.            WaitVbl;
  208.            Line(X1,Y1,X2,Y2,Col);
  209.            X1:=X1+Ix1;
  210.            Y1:=Y1+Iy1;
  211.            X2:=X2+Ix2;
  212.            Y2:=Y2+Iy2;
  213.            If (X1<4) Or (X1>315) Then Ix1:=-Ix1;
  214.            If (Y1<5) Or (Y1>195) Then Iy1:=-Iy1;
  215.            If (X2<4) Or (X2>315) Then Ix2:=-Ix2;
  216.            If (Y2<5) Or (Y2>195) Then Iy2:=-Iy2;
  217.            If Col=254 Then Col:=1;
  218.            Inc(Col);
  219.            RotatePal(Pal1,1,254);
  220.            SetPalette(Pal1);
  221.            If KeyPressed Then
  222.            Begin
  223.                 C:=Readkey;
  224.                 If C=' ' Then
  225.                 Begin
  226.                      Cls(0);
  227.                      Ix1:=3-Random(6); If Ix1=0 Then Ix1:=1;
  228.                      Iy1:=3-Random(6); If Iy1=0 Then Iy1:=1;
  229.                      Ix2:=3-Random(6); If Ix2=0 Then Ix2:=1;
  230.                      Iy2:=3-Random(6); If Iy2=0 Then Iy2:=1;
  231.                 End;
  232.                 If C=Chr(27) Then Exit;
  233.            End;
  234.      Until False;
  235. End;
  236.  
  237. Begin
  238.      Randomize;                       { Resets the random number generator }
  239.      Clrscr;
  240.      Writeln('Hello to another SpellCaster production...');
  241.      Writeln('This one only has lines and circles, and it isn''t');
  242.      Writeln('half as impressive as the Color Blind demo, but');
  243.      Writeln('this issue is already very late...');
  244.      Writeln;
  245.      Writeln('Press SPACE to clear the screen in the lines section');
  246.      Writeln('and ESC to exit any of the sections...');
  247.      Repeat Until Keypressed;
  248.      Initgraph;
  249.      InitLines;
  250.      Lines;
  251.      Circles;
  252.      Closegraph;
  253.      Writeln('Did you liked it ?... ');
  254.      Writeln('I hope you did.');
  255.      Writeln('Write to ''The Mag'':');
  256.      Writeln('Snail Mail: Praceta Carlos Manito Torres, nº4 / 6ºC');
  257.      Writeln('            2900 Setúbal');
  258.      Writeln('                 Portugal');
  259.      Writeln;
  260.      Writeln('E-Mail: Dgan@rnl.ist.utl.pt');
  261.      Writeln;
  262.      Writeln;
  263.      Writeln;
  264.      Repeat Until Keypressed;
  265. End.
  266.